package com.hncc.dms.controller;

import java.util.List;

import com.hncc.dms.domain.DmsNonDrug;
import com.ruoyi.common.constant.UserConstants;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hncc.dms.service.IDmsNonDrugService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;

/**
 * 非药品收费项目管理Controller
 * 
 * @author ruoyi
 * @date 2020-08-13
 */
@RestController
@RequestMapping("/dms/non_drug")
@Api(tags = "非药品收费项目管理接口")
public class DmsNonDrugController extends BaseController
{
    @Resource
    private IDmsNonDrugService dmsNonDrugService;

    /**
     * 查询非药品收费项目管理列表
     */
    @ApiOperation(value = "条件分页查询非药品收费项目管理",httpMethod = "GET")
    @PreAuthorize("@ss.hasPermi('dms:non_drug:list')")
    @GetMapping("/list")
    public TableDataInfo list(DmsNonDrug dmsNonDrug)
    {
        startPage();
        List<DmsNonDrug> list = dmsNonDrugService.selectDmsNonDrugList(dmsNonDrug);
        return getDataTable(list);
    }

    /**
     * 导出非药品收费项目管理列表
     */
    @PreAuthorize("@ss.hasPermi('dms:non_drug:export')")
    @Log(title = "非药品收费项目管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DmsNonDrug dmsNonDrug)
    {
        List<DmsNonDrug> list = dmsNonDrugService.selectDmsNonDrugList(dmsNonDrug);
        ExcelUtil<DmsNonDrug> util = new ExcelUtil<DmsNonDrug>(DmsNonDrug.class);
        return util.exportExcel(list, "non_drug");
    }

    /**
     * 获取非药品收费项目管理详细信息
     */
    @ApiOperation(value = "根据id获取非药品收费项目管理详细信息",httpMethod = "GET",
            notes = "根据id查询非药品收费项目管理")
    @ApiImplicitParam(paramType = "path",name = "id",value = "非药品收费项目管理id",dataType = "Long",required = true)
    @PreAuthorize("@ss.hasPermi('dms:non_drug:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dmsNonDrugService.selectDmsNonDrugById(id));
    }

    /**
     * 根据多个id查询非药品列表
     * @param ids
     * @return
     */
    @GetMapping(value= "/non_drug_ids/{ids}")
    public AjaxResult getNonDrugIds(@PathVariable("ids")String ids){
        return AjaxResult.success(dmsNonDrugService.selectDmsNonDrugByIds(ids));
    }

    /**
     * 根据模板类型获取非药品数据
     * @param recodeType
     * @return
     */
    @GetMapping("/getByRecodeType")
    public AjaxResult getDmsNonDrugListByRecodeType(String recodeType){
        if (recodeType!=null){
            return AjaxResult.success(dmsNonDrugService.selectDmsNonDrugListByRecodeType(Integer.parseInt(recodeType)));
        }
        return AjaxResult.success(dmsNonDrugService.selectDmsNonDrugListByRecodeType(null));
    }

    /**
     * 新增非药品收费项目管理
     */
    @ApiOperation(value = "新增",httpMethod = "POST", notes = "新增非药品收费项目管理")
    @ApiImplicitParam(name = "dmsNonDrug", value = "新增非药品收费项目管理", dataType = "DmsNonDrug")
    @PreAuthorize("@ss.hasPermi('dms:non_drug:add')")
    @Log(title = "非药品收费项目管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsNonDrug dmsNonDrug)
    {
        if(UserConstants.NOT_UNIQUE.equals(dmsNonDrugService.checkUserNameUnique(dmsNonDrug.getName(),dmsNonDrug.getId()))){
            return AjaxResult.error("新增结算类别'" + dmsNonDrug.getName() + "'失败，该决算类别已存在");
        }
        return toAjax(dmsNonDrugService.insertDmsNonDrug(dmsNonDrug));
    }

    /**
     * 修改非药品收费项目管理
     */
    @ApiOperation(value = "修改", httpMethod = "PUT", notes = "修改非药品收费项目管理")
    @ApiImplicitParam(name = "dmsNonDrug", value = "修改非药品收费项目管理", dataType = "DmsNonDrug")
    @PreAuthorize("@ss.hasPermi('dms:non_drug:edit')")
    @Log(title = "非药品收费项目管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsNonDrug dmsNonDrug)
    {
        if(UserConstants.NOT_UNIQUE.equals(dmsNonDrugService.checkUserNameUnique(dmsNonDrug.getName(),dmsNonDrug.getId()))){
            return AjaxResult.error("新增结算类别'" + dmsNonDrug.getName() + "'失败，该决算类别已存在");
        }
        return toAjax(dmsNonDrugService.updateDmsNonDrug(dmsNonDrug));
    }

    /**
     * 删除非药品收费项目管理
     */
    @ApiOperation(value = "批量删除", httpMethod = "DELETE", notes = "根据ids删除非药品收费项目管理")
    @ApiImplicitParam(paramType = "path",name = "ids",value = "非药品收费项目管理id",dataType = "Long[]",required = true)
    @PreAuthorize("@ss.hasPermi('dms:non_drug:remove')")
    @Log(title = "非药品收费项目管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dmsNonDrugService.deleteDmsNonDrugByIds(ids));
    }
}
